package cn.pzhu.controller.web;

import cn.pzhu.controller.BaseController;
import cn.pzhu.model.User;
import cn.pzhu.services.web.WebOrderServices;

import javax.servlet.http.HttpSession;

/**
 * Created by dongp on 2016/5/10.
 */
public class WebOrderController extends BaseController {

	private WebOrderServices webOrderServices = new WebOrderServices();

	public void addOrder(){
		// 判断用户是否登录
		HttpSession session = getSession();
		User user = (User) session.getAttribute("user");
		if(user == null) {
			redirect("/web/login/login");
			return;
		}

		int id = getParaToInt("id");
		int quantity = getParaToInt("quantity");
		String logisticID = getPara("logisticsID");
		String address = getPara("address");
		String postCode = getPara("postCode");
		String recipient = getPara("recipient");
		String phone = getPara("phone");
		String transport = getPara("transport");
		boolean res = webOrderServices.addOrder(id,quantity,logisticID,address,postCode,recipient,phone,transport,user);
		if(res) {
			render("order/success.jsp");
		}else{
			render("order/failue.jsp");
		}
	}

}
